#include <unordered_map>
#include <vector>
using namespace std;

class Solution {
public:
  vector<int> twoSum(vector<int> &nums, int target) {
    unordered_map<int, int> numMap;
    vector<int> res;
    for (int i = 0; i < nums.size(); ++i) {
      numMap.insert({nums[i], i});
    }
    for (int i = 0; i < nums.size(); ++i) {
      int another = target - nums[i];
      if (numMap.find(another) != numMap.end() && numMap[another] != i) {
        res.push_back(i);
        res.push_back(numMap[another]);
        break;
      }
    }
    return res;
  }
};
